﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Windows.Forms;

namespace WindowsApplication1
{
    public partial class 注册 : Form
    {
        public 注册()
        {
            InitializeComponent();
        }

        private void 注册_Load(object sender, EventArgs e)
        {
            MessageBox.Show("注册信息全部填写！");

        }


        private void button1_Click(object sender, EventArgs e)
        {
            c_name.ReadOnly = true;
            if (u_name.Text == "" || pwd.Text == "" || phone.Text == "" || n_pwd.Text == "" || name.Text == "" || id.Text == "" || address.Text == "")
            {
                MessageBox.Show("全部填写，不能有为空的！!");

            }
            if (id.TextLength < 15 || id.TextLength > 18)
            {
                MessageBox.Show("身份证号码必须是15或18位！");
            }
            else
            {
                if (pwd.Text != n_pwd.Text)
                {
                    MessageBox.Show("确认密码和密码要一致！");
                }

                else
                {
                    string ls_sql = "", ls_code, ls_name, ls_pwd, ls_npwd, ls_cd, ls_cd2, ls_cd3, ls_cd4;
                    ls_code = c_name.Text.Trim();
                    ls_name = u_name.Text.Trim();
                    ls_pwd = pwd.Text.Trim();
                    ls_npwd = n_pwd.Text.Trim();
                    ls_cd = name.Text.Trim();
                    ls_cd2 = id.Text.Trim();
                    ls_cd3 = phone.Text.Trim();
                    ls_cd4 = address.Text.Trim();
                    ls_sql = "insert into 管理员信息表 values('" + ls_code + "','" + ls_name + "','" + ls_pwd + "','" + ls_cd + "','" + ls_cd2 + "','" + ls_cd3 + "','" + ls_cd4 + "');";

                    string str_connstring;
                    str_connstring = ConfigurationManager.AppSettings["sqlconn1"];

                    SqlConnection myconn = new SqlConnection();
                    myconn.ConnectionString = str_connstring;
                    myconn.Open();
                    SqlCommand mycommand = new SqlCommand(ls_sql, myconn);
                    MessageBox.Show("注册成功！");
                    mycommand.ExecuteNonQuery();
                    myconn.Close();
                }
            }

        }

        private void button3_Click(object sender, EventArgs e)
        {
            this.Close();
        }


    }
}